package iengine.client;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.RootPanel;
/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Invoice_engine implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final GreetingServiceAsync greetingService = GWT
			.create(GreetingService.class);

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		// Main layout container
		Viewport container = new Viewport();
		BorderLayout layout = new BorderLayout();
	    container.setLayout(layout);  
	    container.setStyleAttribute("padding", "10px");  
	  
	    ContentPanel north = new ContentPanel();
	    north.setIcon(Resources.ICONS.connect());
	    north.setHeading("INVOICE-ENGINE");
	    ContentPanel west = new ContentPanel();  
//	    ContentPanel center = new ContentPanel();  
//	    center.setHeading("BorderLayout Example");  
//	    center.setScrollMode(Scroll.AUTOX);
	    TabPanel center = new TabPanel();
	    TabItem invoice = new TabItem("Invoice");
	    
	    final Window window = new Window();  
	    window.setSize(500, 300);  
	    window.setPlain(true);  
	    window.setModal(true);  
	    window.setBlinkModal(true);  
	    window.setHeading("Add Invoice");  
	    window.setLayout(new FitLayout());
	    window.addText("-invoice id");
	    window.addText("-invoice id");
	    window.addText("-invoice id");
	    
	    ToolBar toolBarInvoice = new ToolBar();
	    Button addInvoice = new Button("Add Invoice", new SelectionListener<ButtonEvent>() {  
	        @Override  
	        public void componentSelected(ButtonEvent ce) {  
	          window.show();  
	        }  
	      });
	    addInvoice.setIcon(Resources.ICONS.add());
	    toolBarInvoice.add(addInvoice);
	    Button invoiceListPDF = new Button("Export list as PDF");
	    invoiceListPDF.setIcon(Resources.ICONS.album());
	    toolBarInvoice.add(invoiceListPDF);
	    invoice.add(toolBarInvoice);  
	    
	    center.add(invoice);
	    
	    TabItem timesheet = new TabItem("Timesheet");
	    
	    final Window windowTimesheet = new Window();  
	    windowTimesheet.setSize(500, 300);  
	    windowTimesheet.setPlain(true);  
	    windowTimesheet.setModal(true);  
	    windowTimesheet.setBlinkModal(true);  
	    windowTimesheet.setHeading("Add Timesheet");  
	    windowTimesheet.setLayout(new FitLayout());
	    
	    ToolBar toolBarTimesheet = new ToolBar();
	    Button addTimesheet = new Button("Add Timesheet", new SelectionListener<ButtonEvent>() {  
	        @Override  
	        public void componentSelected(ButtonEvent ce) {
	        	windowTimesheet.show();  
	        }  
	      });
	    addTimesheet.setIcon(Resources.ICONS.add());
	    toolBarTimesheet.add(addTimesheet);
	    timesheet.add(toolBarTimesheet);  
	    
	    center.add(timesheet);
	      
	  
	    FlexTable table = new FlexTable();  
	    table.getElement().getStyle().setProperty("margin", "10px");  
	    table.setCellSpacing(8);  
	    table.setCellPadding(4);  
	    
//	    center.add(table);  
	  
	    ContentPanel east = new ContentPanel();  
	    ContentPanel south = new ContentPanel();  
	  
	    BorderLayoutData northData = new BorderLayoutData(LayoutRegion.NORTH, 100);  
	    northData.setCollapsible(true);  
	    northData.setFloatable(true);  
	    northData.setHideCollapseTool(true);  
	    northData.setSplit(true);  
	    northData.setMargins(new Margins(0, 0, 5, 0));  
	  
	    BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 150);  
	    westData.setSplit(true);  
	    westData.setCollapsible(true);  
	    westData.setMargins(new Margins(0,5,0,0));  
	  
	    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(0));  
	  
	    BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.EAST, 150);  
	    eastData.setSplit(true);  
	    eastData.setCollapsible(true);  
	    eastData.setMargins(new Margins(0,0,0,5));  
	  
	    BorderLayoutData southData = new BorderLayoutData(LayoutRegion.SOUTH, 100);  
	    southData.setSplit(true);  
	    southData.setCollapsible(true);  
	    southData.setFloatable(true);  
	    southData.setMargins(new Margins(5, 0, 0, 0));  
	  
	    container.add(north, northData);  
	    container.add(west, westData);  
	    container.add(center, centerData);  
	    container.add(east, eastData);  
	    container.add(south, southData);
	    
		RootPanel.get().add(container);
	}
}
